package com.ap.core.business.message.ldap.handler.impl;

import com.ap.core.business.message.ldap.handler.LdapHandler;
import com.ap.core.ldap.dao.api.LdapZappUserDao;
import com.ap.core.ldap.domain.LdapZappUser;
import com.ap.core.message.manageconsumer.info.RequestRegisterConsumerTypeInfo;

/**
 * Implementation class for {@link LdapHandler<RequestRegisterConsumerTypeInfo></>}
 */
public class ZappConsumerLdapHandler implements LdapHandler<RequestRegisterConsumerTypeInfo>{

    private LdapZappUserDao ldapZappUserDao;
    private String consumerUsersTree;

    @Override
    public void handleLdapEntry(RequestRegisterConsumerTypeInfo request, Long id) {
        final String commonName = "ZAPP" + id;
        final LdapZappUser zappUser = new LdapZappUser();
        zappUser.setPassword(request.getRegistrationInfo().getCredentials().getPassword());
        zappUser.setMobileNumber(request.getRegistrationInfo().getMobNb());
        zappUser.setLastName(commonName);
        zappUser.setFirstName(request.getRegistrationInfo().getCredentials().getEmailId());
        zappUser.setCommonName(commonName);
        zappUser.setEmailId(request.getRegistrationInfo().getCredentials().getEmailId());
        zappUser.setUserName(commonName);
        zappUser.setAgreedTermsAndConditions("No");
        zappUser.setUserHash(request.getRegistrationInfo().getCredentials().getSalt());

        ldapZappUserDao.checkThenPersistAndAddAttribute(zappUser, "uniquemember", consumerUsersTree);


    }

    public void setLdapZappUserDao(LdapZappUserDao ldapZappUserDao) {
        this.ldapZappUserDao = ldapZappUserDao;
    }

    public void setConsumerUsersTree(String consumerUsersTree) {
        this.consumerUsersTree = consumerUsersTree;
    }
}
